from django.http import JsonResponse
from django.db import models
from django.utils import timezone
import os


class TableModel(models.Model):
    id = models.AutoField(primary_key=True)
    created_at = models.DateTimeField(auto_now_add=True)
    deleted_at = models.DateTimeField(null=True, blank=True)

    class Meta:
        abstract = True


def json_responce(data:dict,status=200,safe=True):
    return JsonResponse(data=data,status=status,safe=safe)

class ApiResponse:
    @staticmethod
    def success(data=None, message=None, status=200,code=200):
        return api_response(data=data, message=message, status=status,code=code)
    
    @staticmethod
    def fail(message=None, status=200,code=400):
        return api_response(message=message, status=status,code=code)
def api_response(data=None, message=None, status=200,code=200):
    response_data = {
        'code':code,
        'message': message,
        'data': data
    }
    return JsonResponse(response_data, status=status)


def create_directories_if_not_exist(paths):
    for path in paths:
        if not os.path.exists(path):
            os.makedirs(path)
            print(f"创建了目录：{path}")
        else:
            print(f"目录已存在：{path}")
